﻿Public Class Customers
    Dim item As ListViewItem
    Sub listdata()
        If Not rs.EOF Then
            ListView1.Items.Clear()
            rs.MoveFirst()
            Do While Not rs.EOF
                item = ListView1.Items.Add(rs.Fields("CustomerNo").Value)
                item.SubItems.Add(rs.Fields("Name1").Value)
                item.SubItems.Add(rs.Fields("Address").Value)
                item.SubItems.Add(rs.Fields("City").Value)
                rs.MoveNext()

            Loop
        Else
            ListView1.Items.Clear()

        End If
        rs.Close()
        rs = Nothing

    End Sub

    Private Sub Customers_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Module1.connect()
        rs = New ADODB.Recordset
        rs.Open("select * from customers", cn, 3, 2)
        Me.listdata()
    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        rs = New ADODB.Recordset
        rs.Open("select * from customers", cn, 3, 2)
        rs.AddNew()

        rs.Fields("Name1").Value = TextBox4.Text
        rs.Fields("Address").Value = TextBox3.Text
        rs.Fields("City").Value = TextBox2.Text
        rs.Update()
        rs.Close()
        rs = Nothing
        MsgBox("Adding Successful")
        rs = New ADODB.Recordset
        rs.Open("select * from customers", cn, 3, 2)
        Me.listdata()
     


    End Sub

 
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        MainScreen.Show()
        Me.Close()

    End Sub

    Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
        TextBox5.Visible = True
        TextBox5.Text = ListView1.FocusedItem.Text
    End Sub

    Private Sub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged
        rs = New ADODB.Recordset
        rs.Open("SELECT * from customers where customerno = " & TextBox5.Text & "", cn, 3, 2)
        If Not rs.EOF Then
            TextBox4.Text = rs.Fields("name1").Value
            TextBox3.Text = rs.Fields("address").Value
            TextBox2.Text = rs.Fields("city").Value
        End If
        rs.Close()
        rs = Nothing
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        rs = New ADODB.Recordset
        rs.Open("SELECT * from customers where customerno = " & TextBox5.Text & "", cn, 3, 2)
        rs.Fields("Name1").Value = TextBox4.Text
        rs.Fields("Address").Value = TextBox3.Text
        rs.Fields("City").Value = TextBox2.Text
        rs.Update()
        rs.Close()
        rs = Nothing
        MsgBox("Editing Successful")
        rs = New ADODB.Recordset
        rs.Open("select * from customers", cn, 3, 2)
        Me.listdata()
    End Sub

    Private Sub Button4_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        TextBox5.Visible = False
        TextBox4.Text = ""
        TextBox3.Text = ""
        TextBox2.Text = ""
    End Sub
End Class